﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Action_Edit : BasePage
{
    private int actionId;
    protected void Page_Load(object sender, EventArgs e)
    {
        UserPower.CheckAction((int)FreeHouse.Power.Actions.TAction.Edit);
        int.TryParse(Request.QueryString["id"], out actionId);
        if (!IsPostBack) BindData();
    }
    protected void save_Click(object sender, EventArgs e)
    {
        FreeHouse.Model.TAction action = new FreeHouse.Model.TAction();
        action.ActionClassID = int.Parse(ActionClassID.SelectedValue);
        action.MethodName = ActionName.Text.Trim();
        action.Description = Server.HtmlEncode(Description.Value);
        action.ActionID = actionId;
        error.Items.Clear();
        error.Style.Add("color", "#F00");
        if (action.ActionClassID == 0)
            error.Items.Add(new ListItem("填写action 所胡Action类"));
        if (action.MethodName == "")
            error.Items.Add(new ListItem("填写MethodName"));
        if (error.Items.Count == 0)
        {
            new FreeHouse.BLL.TAction().Update(action);
            error.Items.Add(new ListItem("action 修改成功."));                
        }
    }

    protected void BindData()
    {
        ActionClassID.DataSource = new FreeHouse.BLL.TActionClass().GetList(100000, "", "ClassName asc");
        ActionClassID.DataTextField = "ClassName";
        ActionClassID.DataValueField = "ActionClassID";
        ActionClassID.DataBind();
        ActionClassID.Items.Insert(0, new ListItem("请选择...", "0"));
        FreeHouse.Model.TAction action = new FreeHouse.BLL.TAction().GetModel(actionId);
        if (action != null)
        {
            ActionClassID.SelectedValue = action.ActionClassID.ToString();
            ActionName.Text = action.MethodName.Trim();
            Description.Value = action.Description;
        }

    }
}
